﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using WpfStarterKit.Framework.Navigation;

namespace WpfStarterKit.Framework.Util
{
    /// <summary>
    /// The common exception handler
    /// </summary>
    public class ExceptionHandler
    {
        /// <summary>
        /// Handle an exception
        /// </summary>
        /// <param name="exception">The exception raised</param>
        /// <param name="handler">A delegate for the method where the exception occured</param>
        /// <param name="displayError">Whether to display the error in the common error dialog</param>
        /// <param name="catchingType">Type that caught the exception</param>
        public virtual void HandleException(Exception exception, Delegate handler, bool displayError, MemberInfo catchingType)
        {
            string declaringTypeName = null;
            if (handler != null)
            {
                declaringTypeName = handler.Method.DeclaringType.Name;
            }

            HandleException(exception, declaringTypeName, displayError, catchingType);
        }

        /// <summary>
        /// Handle an exception
        /// </summary>
        /// <param name="exception">The exception raised</param>
        /// <param name="declaringTypeName">Type where the exception occurred</param>
        /// <param name="displayError">Whether to display the error in the common error dialog</param>
        public virtual void HandleException(Exception exception, string declaringTypeName, bool displayError)
        {
            HandleException(exception, declaringTypeName, displayError, null, null);
        }

        /// <summary>
        /// Handle an exception
        /// </summary>
        /// <param name="exception">The exception raised</param>
        /// <param name="declaringTypeName">Type where the exception occurred</param>
        /// <param name="displayError">Whether to display the error in the common error dialog</param>
        /// <param name="message">Message to display in the error box</param>
        public virtual void HandleException(Exception exception, string declaringTypeName, bool displayError, string message)
        {
            HandleException(exception, declaringTypeName, displayError, null, message);
        }

        /// <summary>
        /// Handle an exception
        /// </summary>
        /// <param name="exception">The exception raised</param>
        /// <param name="declaringTypeName">Type where the exception occurred</param>
        /// <param name="displayError">Whether to display the error in the common error dialog</param>
        /// <param name="catchingType">Type that caught the exception</param>
        public virtual void HandleException(Exception exception, string declaringTypeName, bool displayError, MemberInfo catchingType)
        {
            HandleException(exception, declaringTypeName, displayError, catchingType, null);
        }

        /// <summary>
        /// Handle an exception
        /// </summary>
        /// <param name="exception">The exception raised</param>
        /// <param name="declaringTypeName">Type where the exception occurred</param>
        /// <param name="displayError">Whether to display the error in the common error dialog</param>
        /// <param name="catchingType">Type that caught the exception</param>
        /// <param name="message">Message to display in the error box</param>
        public virtual void HandleException(Exception exception, string declaringTypeName, bool displayError, MemberInfo catchingType, string message)
        {
            
        }

        /// <summary>
        /// Handles the error.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="displayMessage">The display message.</param>
        /// <param name="detailedErrorMessage">The detailed error message.</param>
        public virtual void HandleError(string source, string displayMessage, string detailedErrorMessage)
        {
        }
    }
}
